package com.itheima.a01plymorphismdemo1;

public class Person {
    //变量
    private String name;
    private int age;

    //构造方法

    public Person() {}

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }


    //set/get

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    //方法
    public void keepPet(Animal a,String something) {
        if(a instanceof Dog d){
            System.out.println("年龄为"+getAge()+"岁的老王养了一只"+d.getColor()
                    +"颜色的"+d.getAge()+"岁的狗");
            d.eat(something);
        }else if(a instanceof Cat c) {
            System.out.println("年龄为"+getAge()+"岁的老王养了一只"+c.getColor()
                    +"颜色的"+c.getAge()+"岁的猫");
            c.eat(something);
        }
    }
}
